package com.atguigu.tingshu.order.api;

import com.atguigu.tingshu.common.login.GuiguLogin;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.common.util.AuthContextHolder;
import com.atguigu.tingshu.order.service.OrderInfoService;
import com.atguigu.tingshu.vo.order.OrderInfoVo;
import com.atguigu.tingshu.vo.order.TradeVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@Tag(name = "订单管理")
@RestController
@RequestMapping("api/order")
@SuppressWarnings({"all"})
public class OrderInfoApiController {

	@Autowired
	private OrderInfoService orderInfoService;


	/**
	 * 订单确认(数据汇总)
	 * @param tradeVo
	 * @return
	 */
	@Operation(summary = "订单确认(数据汇总)")
	@GuiguLogin
	@PostMapping("/orderInfo/trade")
	public Result<OrderInfoVo> getOrderInfo(@RequestBody TradeVo tradeVo){

		Long userId = AuthContextHolder.getUserId();

		OrderInfoVo orderInfoVo = orderInfoService.getOrderInfo(tradeVo,userId);

		return Result.ok(orderInfoVo);
	}


	/**
	 * 提交订单
	 * @param orderInfoVo
	 * @return
	 */
	@GuiguLogin
	@Operation(summary = "提交订单")
	@PostMapping("/orderInfo/submitOrder")
	public Result<Map<String,String>> submitOrder(@RequestBody OrderInfoVo orderInfoVo){

		Long userId = AuthContextHolder.getUserId();

		Map<String,String> map = orderInfoService.submitOrder(userId,orderInfoVo);

		return Result.ok(map);
	}

}

